function BGobj = createMap(Q, project_id)

%creates a graph of relationaships given the project_id. 
%uses biograph.m to generate a graph from a 
%Q = is a struct with url and key
%project_id = project id of the project to map
%
%Romesh Stanislaus May 2009

try
    P = projectView(Q, project_id); %all collections in project
    if size(P,1) == 0
        error('No Project exists. Please if check the id and try again...')
    end
catch
    error('Please Check if project_id exists and try again...')
end
V.project_id = project_id; %create struct for selectCommon
R =  selectCommon(Q, 'rules', V); %selectRules(Q, ruleID); %get all rules for the project_id
subjects = {R(:).subject}'; %get all the subjects from the rules
objects = {R(:).object}'; %get all the objects from the rules
uniSubjObjs = unique([unique(subjects);unique(objects)]); %get unique subjs & objs
%add the project_id to the list as it wont be there or project_name here
uniSubjObjs{size(uniSubjObjs,1)+1,1} = num2str(project_id);
level_1_matrix = zeros(size(uniSubjObjs,1),size(uniSubjObjs,1)); %genrtate matrix of 0
try
    collections = {P(:).label}'; %collections +proj_id
catch
    %if label field is absent try this
    collections = {P(:).entity}'; %collections +proj_id
end
%fill the connection matrix
disp('Generating Connection Matrix...')
S = fillMatrix(level_1_matrix, uniSubjObjs, R, unique(subjects), collections, project_id); 

% %generate biograh
disp('Generating graph...')
BGobj=biograph(S.matrix,S.M_name);
disp('Node classification...')
%call beautyfyMap_CR make collections and rule object nodes more visible
BGobj = beautyfyMap_CoRu(BGobj, collections, unique(objects), project_id);
BGobj.LayoutType = 'radial';
dolayout(BGobj); % need to call this everytime u change 
BGobj.view
% get(BGobj.nodes,'ID')
